<?php
	
	include("includes/header.php");
	include("includes/conf.php");
	
	echo '	<table border="1">
				<caption>Evaluation de la recherche</caption>

				<thead> <!-- En-tête du tableau -->
				  <tr>
					   <th>Requete</th>
					   <th>5 r&eacute;sultats</th>
					   <th>10 r&eacute;sultats</th>
					   <th>25 r&eacute;sultats</th>
				   </tr>
				</thead>
				<tbody>
	';
	
	$xml = simplexml_load_file('./test/Queries/queries.xml');
	
	// Pour chaque requête du fichier queries
	$threatedRequest = 1;
	foreach($xml->query as $queryXML) {
		echo "<br/>****************** Requête ".$threatedRequest." ***************";
		echo "<tr>";
		
		$queryID = substr($queryXML['id'],-2);
		$queryText = $queryXML->text;
		$queryNarrative = $queryXML->narrative;
		
		echo "<td>qrel".$queryID."</td>";
		echo "<br/>INTITULE : ".$queryText;
		
		//******************** 5 ********************
		$nbResults = 5;
		$results = search($queryText);
		$tabResults = stock_node_path_results($results, $nbResults);
		$tabResults2 = read_and_stock_node_path_file("./test/qrels/qrel".$queryID.".txt");
		$tabDiff = array_diff($tabResults, $tabResults2);
		$resultPourcent = 100 - (count($tabDiff)/count($tabResults))*100;
		echo "<td>".(count($tabResults)-count($tabDiff))." sur ".count($tabResults)."(".$resultPourcent."%)</td>";
		
		
		 //******************** 10 ********************
		$nbResults = 10;
		$tabResults = stock_node_path_results($results, $nbResults);
		$tabResults2 = read_and_stock_node_path_file("./test/qrels/qrel".$queryID.".txt");
		$tabDiff = array_diff($tabResults, $tabResults2);
		$resultPourcent = 100 - (count($tabDiff)/count($tabResults))*100;
		echo "<td>".(count($tabResults)-count($tabDiff))." sur ".count($tabResults)."(".$resultPourcent."%)</td>";
		
		
		//******************** 25 ********************
		$nbResults = 25;
		$tabResults = stock_node_path_results($results, $nbResults);
		$tabResults2 = read_and_stock_node_path_file("./test/qrels/qrel".$queryID.".txt");
		$tabDiff = array_diff($tabResults, $tabResults2);
		$resultPourcent = 100 - (count($tabDiff)/count($tabResults))*100;
		echo "<td>".(count($tabResults)-count($tabDiff))." sur ".count($tabResults)."(".$resultPourcent."%)</td>";
		
		echo "</tr>"; 
		$threatedRequest++;
	}
	
	echo "</tbody>
		</table>";
		
	/* echo '	<table border="1">
				<caption>Evaluation de la recherche sans onthology</caption>

				<thead> <!-- En-tête du tableau -->
				  <tr>
					   <th>Requete</th>
					   <th>5 r&eacute;sultats</th>
					   <th>10 r&eacute;sultats</th>
					   <th>25 r&eacute;sultats</th>
				   </tr>
				</thead>
				<tbody>
	';
	
	// ***** RECHERCHE SIMPLE
	foreach($xml->query as $queryXML) {
	
		echo "<tr>";
		
		$queryID = substr($queryXML['id'],-2);
		$queryText = $queryXML->text;
		$queryNarrative = $queryXML->narrative;
		
		echo "<td>qrel".$queryID."</td>";
		
		//******************** 5 ********************
		$nbResults = 5;
		$results = searchSimple($queryText);
		$tabResults = stock_node_path_results($results, $nbResults);
		$tabResults2 = read_and_stock_node_path_file("./test/qrels/qrel".$queryID.".txt");
		$tabDiff = array_diff($tabResults, $tabResults2);
		$resultPourcent = 100 - (count($tabDiff)/count($tabResults))*100;
		echo "<td>".(count($tabResults)-count($tabDiff))." sur ".count($tabResults)."(".$resultPourcent."%)</td>";
		
		
		 //******************** 10 ********************
		$nbResults = 10;
		$tabResults = stock_node_path_results($results, $nbResults);
		$tabResults2 = read_and_stock_node_path_file("./test/qrels/qrel".$queryID.".txt");
		$tabDiff = array_diff($tabResults, $tabResults2);
		$resultPourcent = 100 - (count($tabDiff)/count($tabResults))*100;
		echo "<td>".(count($tabResults)-count($tabDiff))." sur ".count($tabResults)."(".$resultPourcent."%)</td>";
		
		
		//******************** 25 ********************
		$nbResults = 25;
		$tabResults = stock_node_path_results($results, $nbResults);
		$tabResults2 = read_and_stock_node_path_file("./test/qrels/qrel".$queryID.".txt");
		$tabDiff = array_diff($tabResults, $tabResults2);
		$resultPourcent = 100 - (count($tabDiff)/count($tabResults))*100;
		echo "<td>".(count($tabResults)-count($tabDiff))." sur ".count($tabResults)."(".$resultPourcent."%)</td>";
		
		echo "</tr>"; 
	}
	
	echo "</tbody>
		</table>"; */
		
	include("includes/footer.php");

?>
